

import { _decorator, Component, Node, Label, macro, tween, Tween, Vec3, RichText } from 'cc';
import { UiForm } from './uiForm';
const { ccclass, property } = _decorator;
@ccclass
export default class ToastForm extends UiForm {

    @property(Label)
    msgText: Label = null!;

    @property(RichText)
    msgRichText: RichText = null!;


    constructor() {
        super();
    }
    start() {

    }


    private showTween: Tween<Node> = null;
    show(msg: string, isRich: boolean = false) {
        this.node.setSiblingIndex(9999);
        if (isRich) {
            this.msgRichText.string = msg;
            this.msgText.node.active = false;
            this.msgRichText.node.active = true;
        }
        else {
            this.msgText.string = msg;
            this.msgText.node.active = true;
            this.msgRichText.node.active = false;
        }
        this.node.active = true;
        if (this.showTween) {
            this.showTween.stop();
            this.showTween = null;
        }
        this.showTween = tween(this.node)
            .to(0.1, { scale: new Vec3(1.2, 1.2, 1.2) }, { easing: 'bounceInOut' })
            .to(0.1, { scale: new Vec3(1, 1, 1) }, { easing: 'bounceInOut' })
            .union()
            .start();

        this.scheduleOnce(this.hide, 1)
    }
    hide() {
        // uiManager.hideUIForm(UIForms.ToastForm, null)
        this.node.active = false;
    }
}
